<script>
	export default {
		onLaunch: function(launch) {
			// 小程序过滤强制登录链接
			const MPfilterPath = [
				'/tie-in/tie-in-preview',
				'/my/user-coupon/user-coupon-receive',
			]
			// H5过滤强制登录链接
			const H5FilterPath = [
				'pages/product-info/product-info',
				'pages/package/house-info',
				'pages/package/n98-info',
				'tie-in/tie-in-preview',
				'pages/events/year-end',
				'my/user-coupon/user-coupon-receive',
				'my/my-order/order-details/order-sales-details',
				'my/my-order/after_sale_form/after_sale_form'
			]
			// #ifdef APP-PLUS || H5
			if (launch.path == undefined) {
				uni.showToast({
					icon: 'none',
					title: '页面不存在,正在返回首页',
					duration: 2000
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}, 2000)
			}
			// #endif
			// #ifdef H5
			let redirect_url = location.href.split('#')[0]
			this.$u.api.GetShare({
				url: redirect_url
			}).then(res => {
				this.$wx.config({
					debug: false,
					appId: res.datas.appId,
					timestamp: res.datas.timestamp,
					signature: res.datas.signature,
					nonceStr: res.datas.nonceStr,
					jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
				})
			})
			if (uni.getStorageSync('newurl').indexOf('login/login') != -1 || uni.getStorageSync('newurl').indexOf(
					'sendCode/sendCode') != -1 || uni.getStorageSync('newurl').indexOf('verification/verification') != -1) {
				uni.removeStorageSync('newurl')
			}
			if (launch.query.parent_id) {
				uni.setStorageSync('parent_id', launch.query.parent_id)
				let url = '';
				for (let i in launch.query) {
					url += i + "=" + launch.query[i] + "&"
				}
				uni.setStorageSync('newurl', '/' + launch.path + '?' + url.substring(0, url.length - 1))
			}
			if (!uni.getStorageSync('userInfo')) {
				uni.setStorageSync('review', false)
				// 判断是否从分享的链接点进来的商品详情，如果是则不跳转登录
				if (H5FilterPath.indexOf(launch.path) != -1) {
					return false
				}
				uni.reLaunch({
					url: '/pages/login/login',
				})
			} else {
				// console.log(typeof uni.getStorageSync('userInfo'))
				if (typeof uni.getStorageSync('userInfo') !== 'string') {
					uni.removeStorageSync('userInfo')
				}
				if (H5FilterPath.indexOf(launch.path) != -1) {
					return false
				}
				this.$u.api.StoreShow().then(res => {
					if (res.datas.is_open == 1) {
						uni.setStorageSync('is_open', true)
					} else {
						uni.setStorageSync('is_open', false)
					}
				})
			}
			// #endif
			// 是否开启强制登录  缓存review字段判断是否在审核状态
			// is_review || is_review_next  每次版本更新交替使用
			if (!uni.getStorageSync('userInfo')) {
				// // #ifdef MP-WEIXIN
				// if(uni.getExtConfigSync().appid!=='wx9528157f77bff5d2'){
				// 	setTimeout(() => {
				// 		let path = uni.getStorageSync('newurl').slice(0,uni.getStorageSync('newurl').indexOf('?'))
				// 		if(MPfilterPath.indexOf(path)!=-1){
				// 			return false
				// 		}
				// 		setTimeout(() => {
				// 			this.$u.api.WeChat().then(res => {
				// 				if(res.datas.is_review_next && res.datas.is_review_next == 1){
				// 					uni.setStorageSync('review',true)
				// 					if(uni.getExtConfigSync().appid==='wx9f2da8a90bb750f7'){
				// 						uni.switchTab({
				// 							url: '/pages/classify/classify'
				// 						})
				// 					}
				// 					return false
				// 				}else if (res.datas.is_show == 2) {
				// 					uni.setStorageSync('review',false)
				// 					uni.reLaunch({
				// 						url: '/pages/login/login',
				// 					})
				// 				}
				// 			})
				// 		},500)
				// 	},1000)
				// }
				// // #endif
				// #ifdef APP-PLUS
				this.$u.api.WeChat().then(res => {
					console.log(res, '`````````````````')
					if (res.datas.is_review_app && res.datas.is_review_app == 1) {
						uni.setStorageSync('review', true)
						return false
					}
					if (res.datas.is_show_app == 2) {
						uni.setStorageSync('review', false)
						uni.reLaunch({
							url: '/pages/login/app-login',
						})
					}
				})
				// #endif
			} else {
				// 箭牌小程序定制功能，只显示四个栏目，不显示商城，那么这里判断直接跳转tabbar第一个栏目
				// #ifdef MP-WEIXIN
				if (uni.getExtConfigSync().appid === 'wx9f2da8a90bb750f7') {
					uni.switchTab({
						url: '/pages/merchant/merchant'
					})
				} else {
					this.$u.api.StoreShow().then(res => {
						if (res.datas.is_open == 1) {
							uni.setStorageSync('is_open', true)
						} else {
							uni.setStorageSync('is_open', false)
						}
					})
				}
				// #endif
				// #ifdef APP-PLUS || H5
				this.$u.api.StoreShow().then(res => {
					// #ifdef APP-PLUS
					if (res.datas.is_show == 2) {
						uni.switchTab({
							url: '/pages/merchant/merchant'
						})
					}
					// #endif
					if (res.datas.is_open == 1) {
						uni.setStorageSync('is_open', true)
					} else {
						uni.setStorageSync('is_open', false)
					}
				})
				// #endif
			}
		},
		onShow: function() {
			// 小程序更新检测
			// #ifdef MP-WEIXIN
			this.autoUpdate()
			// #endif
		},
		onHide: function() {
			uni.removeStorageSync('newurl')
		},
		onError(onError) {
			this.$throw()
		},
		methods: {
			// 商品详情
			goProInfo(goods_id, isMerchant, tieIn, activityName) {
				if (isMerchant) {
					uni.navigateTo({
						url: '/pages/product-info/product-info?goods_id=' + goods_id + '&isMerchant=' + isMerchant,
						animationDuration: 500
					})
				} else {
					if (tieIn) {
						uni.navigateTo({
							url: '/pages/product-info/product-info?goods_id=' + goods_id + '&tieIn=true',
							animationDuration: 500
						})
					} else if (activityName) {
						uni.navigateTo({
							url: '/pages/product-info/product-info?goods_id=' + goods_id + '&is_activity=' + activityName,
							animationDuration: 500
						})
					} else {
						uni.navigateTo({
							url: '/pages/product-info/product-info?goods_id=' + goods_id,
							animationDuration: 500
						})
					}
				}
			},
			autoUpdate() {
				var self = this
				if (uni.canIUse('getUpdateManager')) {
					const updateManager = uni.getUpdateManager()
					updateManager.onCheckForUpdate(function(res) {
						if (res.hasUpdate) {
							updateManager.onUpdateReady(function() {
								uni.showModal({
									title: '更新提示',
									content: '新版本已经准备好，是否重启应用？',
									success: function(update) {
										if (update.confirm) {
											updateManager.applyUpdate()
										} else if (update.cancel) {
											uni.showModal({
												title: '温馨提示~',
												content: '本次版本更新涉及到新的功能添加，旧版本无法正常访问的哦~',
												success: function(cancelUpdate) {
													self.autoUpdate()
													return;
													if (cancelUpdate.confirm) {
														updateManager.applyUpdate()
													} else if (cancelUpdate.cancel) {
														self.autoUpdate()
													}
												}
											})
										}
									}
								})
							})
							updateManager.onUpdateFailed(function() {
								uni.showModal({
									title: '自动更新失败',
									content: '请您删除当前小程序，重新搜索打开哟~',
								})
							})
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '当前微信版本过低，请升级到最新微信版本！'
					})
				}
			}
		},
		globalData: {
			"defaultMenu": [{
					"pagePath": "/pages/index/index",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/shop.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/shop_hover.png",
					"text": "商城"
				},
				{
					"pagePath": "/pages/classify/classify",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify_hover.png",
					"text": "分类"
				},
				{
					"pagePath": "/pages/tie-in-list/tie-in-list",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case_hover.png",
					"text": "推荐"
				},
				{
					"pagePath": "/pages/my/my",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my_hover.png",
					"text": "我的"
				}
			],
			"merchantMenu": [{
				"pagePath": "/pages/index/index",
				"iconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon1.png?v=1",
				"selectedIconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon2.png?v=1",
				"text": "首页"
			}, {
				"pagePath": "/pages/classify/classify",
				"iconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon3.png?v=2",
				"selectedIconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon4.png?v=2",
				"text": "分类"
			}, {
				"pagePath": "/pages/center/center",
				"iconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon5.png?v=2",
				"selectedIconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon5.png?v=2",
				"text": "中心",
			}, {
				"pagePath": "/pages/car/car",
				"iconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon6.png?v=1",
				"selectedIconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon7.png?v=1",
				"text": "购物车"
			}, {
				"pagePath": "/pages/my/my",
				"iconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon8.png?v=1",
				"selectedIconPath": "https://master.shengejiaju.cn/web/static/new-shop/icon9.png?v=1",
				"text": "我的"
			}],
			// 箭牌tabbar
			"arrowDefaultMenu": [{
					"pagePath": "/pages/classify/classify",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify_hover.png",
					"text": "分类"
				},
				{
					"pagePath": "/pages/tie-in-list/tie-in-list",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case_hover.png",
					"text": "推荐"
				},
				{
					"pagePath": "/pages/my/my",
					"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my.png",
					"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my_hover.png",
					"text": "我的"
				}
			],
			"arrowMerchantMenu": [{
				"pagePath": "/pages/merchant/merchant",
				"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/index.png",
				"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/index_hover.png",
				"text": "首页"
			}, {
				"pagePath": "/pages/classify/classify",
				"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify.png",
				"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/classify_hover.png",
				"text": "分类"
			}, {
				"pagePath": "/pages/tie-in-list/tie-in-list",
				"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case.png",
				"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/case_hover.png",
				"text": "推荐"
			}, {
				"pagePath": "/pages/my/my",
				"iconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my.png",
				"selectedIconPath": "https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/tabbar/my_hover.png",
				"text": "我的"
			}]
		}
	}
</script>

<style lang="scss">
	@font-face {
		font-family: 'din';
		src: url('https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/DIN-Bold.ttf') format('truetype');
	}

	@import "uview-ui/index.scss";

	/*每个页面公共css */
	image {
		vertical-align: top;
	}

	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}

	.merchant-swiper-box .uni-swiper-dot {
		width: 8rpx;
		height: 8rpx;
	}

	.merchant-swiper-box .uni-swiper-dot-active {
		width: 12rpx;
		height: 12rpx;
	}

	.merchant-swiper-box .uni-swiper-dots {
		display: flex;
		align-items: center;
	}

	.car-group-goods .uni-transition,
	.coupon-pop .uni-transition {
		max-height: 80%;
	}

	.fade-out,
	.fade-in {
		max-height: 100% !important;
	}

	.u-cell {
		align-items: center;
	}

	.uni-popup {
		z-index: 999 !important;
	}

	.wx-swiper-dots .wx-swiper-dot {
		width: 6rpx;
		height: 6rpx;
		vertical-align: middle;
		transition: all .5s;
	}

	.wx-swiper-dots .wx-swiper-dot-active {
		width: 8rpx;
		height: 8rpx;
	}
</style>